// 1. 红包
// 2. a-f的所有路径

function redPackage(amount, count, min = 0.1){
    let remining = amount;
    let res = []

    for(let i = 0; i< count; i++){
        if(i === count -1){
            res.push(remining.toFixed(2))
        } else {
            let money = (remining - min * (count - i - 1)).toFixed(2)
            let random = (Math.random() * (money - min) + min).toFixed(2)
            remining = remining - random
            res.push(random)
        }
    }
    for(let i = 0; i<res.length; i++){
        let index= Math.floor(Math.random() * (i+1));
        [res[index], res[i]] = [res[i],res[index]]
    }
    return res;
}
console.log(redPackage(10, 5))


// a-f
function findPath(arr, start, end){
    let map = {};
    arr.forEach(item => {
        const [key, val] = item.split('-')
        if(!map[key]) map[key] = [];
        map[key].push(val)
    })

    let res = [];
    let temp = [];
    let used = new Set();
    var dfs = (current, temp) =>{
        if(current === end){
            res.push(temp)
        }
        used.add(current);
        let list = map[current] || [];
        for(let i = 0; i < list.length; i++){
            if(!used.has(list[i])){
                dfs(list[i], temp.concat(list[i]))
            }
        }
        used.delete(current)
    }
    dfs(start, [start])

    let result = [];
    for(let i = 0; i< res.length; i++){
        let arr = []
        for(let j = 0; j< res[i].length - 1; j++){
            arr.push(`${res[i][j]}-${res[i][j+1]}`)
        }
        result.push(arr)
    }
    return result;
}

let arr = ['a-b', 'b-c','a-d','c-d','d-f']
console.log(findPath(arr, 'a', 'f'))